<!--
/**
 ******************************************************************************
 * File: json_crud_array.html
 * Create Date: November 18, 2011
 * @description: demo use of json_crud_array 
 * @author Md. Ruzdi Islam   
 *****************************************************************************
*/
-->
<!DOCTYPE html>
<html>
    <head>
        <title>JSON Crud Demo use</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="json_crud_array.js" ></script>
    </head>
    <body>
        <div>JSON Crud Demo use</div>
        <script type="text/javascript" >
            
            // prepare a node to add in the array remember "key" is mandatory index
            newnode = {
                key: 'ruzdi',
                title: "Test title 1"
            };
            
            //getting the new node index
            var index = json_crud_array.getNewNodeIndex();            
            
            //add a node to the array
            if(json_crud_array.addNode(index, newnode) == true){
                alert("node added successfully");
            }else{
                alert("node add failed");
            }
            
            // getting total no of element in the array
            alert("Get total node: "+json_crud_array.getTotalNode());
            
            // prepare a node to add in the array remember "key" is mandatory index
            newnode = {
                key: 'mahedi',
                title: "Test title 2"
            };            
            
            //add a node to the array
            if(json_crud_array.addNode(json_crud_array.getNewNodeIndex(), newnode) == true){
                alert("node added successfully");
            }else{
                alert("node add failed");
            }
            
            // getting total no of element in the array
            alert("Get total node : "+json_crud_array.getTotalNode());
            
            // prepare a node to add in the array remember "key" is mandatory index
            newnode = {
                key: 'ruzalin',
                title: "Test title 3"
            };            
            
            //add a node to the array
            if(json_crud_array.addNode(json_crud_array.getNewNodeIndex(), newnode) == true){
                alert("node added successfully");
            }else{
                alert("node add failed");
            }
            
            // getting total no of element in the array
            alert("Get total node : "+json_crud_array.getTotalNode());
            
            
            
            
            // search from array
            var matchList = json_crud_array.partialMatchByKey('ruz');
            if(matchList){
                matchdata = "";
                for(i=0; i<matchList.length; i++ ){
                    matchdata += "Match "+(i+1)+" :  key => "+matchList[i].key+"  ::  title => "+matchList[i].title+"\n"
                }
                alert("Total match found :: "+matchList.length+" \n "+matchdata);
                
            }else{
                alert(" No data found ")
            }
            
            
            // search from array with limit
            var matchList = json_crud_array.partialMatchByKey('ruz',1);
            if(matchList){
                matchdata = "";
                for(i=0; i<matchList.length; i++ ){
                    matchdata += "Match "+(i+1)+" :  key => "+matchList[i].key+"  ::  title => "+matchList[i].title+"\n"
                }
                alert("Total match found (With Limit):: "+matchList.length+" \n "+matchdata);
                
            }else{
                alert(" No data found ")
            }
            
            
            // search from array
            //if(json_crud_array.partialMatchByKey('ruzd', limit)){
                
            //}
            
            
            //check a node exist or not
            if(json_crud_array.isNodeExist('mahedi') != false){
                alert("node exist");
            }else{
                alert("node does not exist !!!!!!!!!!!!!!!!!!!!!");
            }
            
            //check a node exist or not
            if(json_crud_array.isNodeExist('ruzdi') != false){
                alert("node exist");
            }else{
                alert("node does not exist !!!!!!!!!!!!!!!!!!!!!");
            }
            
            
            // getting total no of element in the array
            alert("Get total node : "+json_crud_array.getTotalNode());
            
            //remove node by index
            if(json_crud_array.removeNodeByIndex(1) != false){
                alert("node removed");
            }else{
                alert("node node remove failed !!!!!!!!!!!!!!!!!!!!!");
            }
            
            // getting total no of element in the array
            alert("Get total node : "+json_crud_array.getTotalNode());
            
            
            //remove node by key
            if(json_crud_array.removeNodeByKey('ruzdi') != false){
                alert("node removed");
            }else{
                alert("node node remove failed !!!!!!!!!!!!!!!!!!!!!");
            }
            
            // getting total no of element in the array
            alert("Get total node : "+json_crud_array.getTotalNode());
            
            
        </script>
    </body>
</html>
